<?php

namespace App\Http\Controllers\UserApi;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Services\Api\ClassService;
use App\Http\Requests\UserApi\ClassController\ListsWhere;
use App\Http\Requests\UserApi\ClassController\ClassHomeInfo;
use App\Models\ClassBaseInfo;
use Illuminate\Support\Facades\Log;

class ClassController extends BaseController
{
    //首页课程列表
    public function class_home(Request $request)
    {
        return self::success(ClassService::class_home_lists($request));
    }

    //课程详情
    public function class_home_info(ClassHomeInfo $request)
    {
        return self::success(ClassService::class_home_info($request));
    }

    //课程安排
    public function class_base_info(Request $request)
    {
       // Log::info('测试'.$request);
        return self::success(ClassService::class_base_info($request));
    }

    //課程安排詳情
    public function class_base_info_detail(Request $request){
        return self::success(ClassService::class_base_info_detail($request->input('class_base_info_id'), $request->input('data_time')));
    }

    public function lists_where(ListsWhere $request)
    {
        return self::success(ClassService::where($request->type));
    }

    public function plan_info(Request $request,ClassBaseInfo $baseInfo){
        $data = $baseInfo->where('id',$request->input('class_base_info_id'))
            ->with([
                'class_base'=>function($q){
                    $q->select(['id','class_name']);
                },
                'teacher'=>function($q){
                    $q->select(['id','teacher_name']);
                },
                'classsroom'=>function($q){
                    $q->select(['id','numbering']);
                },
                'store'=>function($q){
                    $q->select(['id','store_name']);
                },
            ])
            ->first();
        return self::success($data);
    }
}
